import { createStore } from 'vuex'
import user from './modules/user'
import createPersistedState from 'vuex-persistedstate'
import admin from './modules/admin';

export default createStore({
  state: {
    changeNetwork:true,
    roleId:'',
    token:''
  },
  getters: {
    // 示例 getter：获取 changeNetwork 值
    getChangeNetwork: state => state.changeNetwork,

    // 示例 getter：获取 roleId 值
    getRoleId: state => state.roleId,

    // 示例 getter：获取 token 值
    getToken: state => state.token,

  },
  mutations: {
    // 示例 mutation：设置 changeNetwork 值
    setChangeNetwork(state, newValue) {
      state.changeNetwork = newValue;
    },

    // 示例 mutation：设置 roleId 值
    setRoleId(state, newValue) {
      state.roleId = newValue;
    },

    // 示例 mutation：设置 token 值
    setToken(state, newToken) {
      state.token = newToken;
    },
    // updateRoleId (state: { roleId: any; }, payload: any) {
    //   state.roleId = payload;
    // }
  },
  actions: {
    // 示例 action：触发 setChangeNetwork mutation
    updateChangeNetwork({ commit }, newValue) {
      commit('setChangeNetwork', newValue);
    },

    // 示例 action：触发 roleId mutation
    updateRoleId({ commit }, newValue) {
      commit('setRoleId', newValue);
    },

    // 示例 action：触发 setToken mutation
    updateToken({ commit }, newToken) {
      commit('setToken', newToken);
    },

  },
  modules: {
    user,
    admin
  },
  plugins: [createPersistedState()] // 应用 vuex-persistedstate 插件
})
